﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace carsitem.kehu
    
{
    public partial class selectpeople : Form
    {
      
        public selectpeople()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }
        private void selectpeople_Load(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=季白\\MSSQLSERVER04;Initial Catalog=SellCars;Integrated Security=True");
            string name = this.NameBox.Text;
            string customersex = "";
            if (this.ManRbt.Checked == true)
            {
                customersex = "男";
            }
            if (this.WmanRbt.Checked == true)
            {
                customersex = "女";
            }
            string number = this.PhoneBox.Text;
            zhengzebiaoda zda = new zhengzebiaoda();

            string sql = "select * from customerTable where 1=1 ";
            if (name != "")
            {
                sql = sql + string.Format(" and customerName='{0}' ", name);
            }
            if (customersex != "")
            {
                sql = sql + string.Format(" and customersex='{0}' ", customersex);
            }
            if (number!="")
            {
                sql = sql + string.Format(" and customernumber='{0}'",number);
            } 
            SqlDataAdapter dap = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            this.guke_dvg.AutoGenerateColumns = false;//设置不自动生成其他列
            dap.Fill(ds);
            DataView dv = ds.Tables[0].DefaultView;
            this.guke_dvg.DataSource = dv;
        }
        private void button1_Click(object sender, EventArgs e)
        {

        }
        private void NameBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void CongBt_Click(object sender, EventArgs e)
        {
            foreach (Control con in this.Controls)//遍历控件类集合
            {
                TextBox text = con as TextBox;//获取TextBox对象
                RadioButton rdo = con as RadioButton;//获取RadioButton对象
                CheckBox che = con as CheckBox;//获取CheckBox对象
                if (text != null)//文本框清空
                {
                    text.Text = "";
                }
                if (che != null)//多选框全不选
                {
                    che.Checked = false;
                }

            }
        }

        private void ManRbt_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void UpdateBt_Click(object sender, EventArgs e)
        {
            try
            {
                int sid = Convert.ToInt32(this.guke_dvg.SelectedRows[0].Cells["customerID"].Value);
                Updatecustomer upcus = new Updatecustomer();
                upcus.cus = sid;
                upcus.ShowDialog();
            }
            catch (Exception )
            {
                MessageBox.Show("文本框不能为空");
                
            }
        }

        private void selectpeople_FormClosed(object sender, FormClosedEventArgs e)
        {
            carsitem.MainInterface.MainInterfaceForm mainInterfaceForm = new carsitem.MainInterface.MainInterfaceForm();//把form1传给form2
            mainInterfaceForm.Show();
            this.Hide();//把自己隐藏了
        }
    }
}
